$(function(){

	addtips = $("#add .validateTips");
	function updateaddTips(t) {
		addtips
			.text(t)
			.addClass('ui-state-highlight');
		setTimeout(function() {
			addtips.removeClass('ui-state-highlight', 1000);
		}, 500);
	};	
	$("#addConfirm").dialog({
		autoOpen : false,
		/*height :300,*/
		width : 40,
		resizable: false,
		modal : true,
		buttons : {
			'确定' : function()
			{
		
			$("button").unbind("click");
			var ltName = $.trim($("#addltName").val());
			var tbesColor = $("input[name='addltColor']").val();
			if(tbesColor.length==0)
				tbesColor="ffffff";
			
			var url="/ag/lwc/saveTbLogType.action";
			var req={ltName:ltName,ltColor:tbesColor};
			var ajax=jQuery.post(url,req,function (data)
				{
			
				if((typeof data.message) == "undefined")
						data = eval("("+data+")");
		
				if(data.message=="save_success")
				{
					$("#add").dialog('close');
					
					$("#addConfirm").dialog('close');
					
					$("#message").text("保存成功");
					$('#message').dialog('open');
					setTimeout("window.location.href='/ag/lwc/findTbLogType.action';",600); 

				}
				else
				{
				
					$("#addConfirm").dialog('close');
					$("#add").dialog('close');
					$("#message").text("保存失败");
					$('#message').dialog('open');
		
				}
				});

			},
			'取消' : function() 
			{
				$(this).dialog('close');
			}
		},
		close : function()
		{
			$("#addltName").val("");
			$("#addltColor").val("");
			updateaddTips("");
			addtips.removeClass('ui-state-highlight');
			$("dialog").dialog('close');
		}
	});
		$("#add").dialog({
			autoOpen : false,
			/*height :300,*/
			width : 400,
			modal : true,
			buttons : {
				'提交' : function()
				{
				//获取增加对话框的内容并验证
				var tbesEventStatus = $.trim($("#addltName").val());
				var tbesColor = $("input[name='addltColor']").val();		
				var cArr = tbesEventStatus.match(/[^x00-xff]/ig);
				var cArr2 = tbesColor.match(/[^x00-xff]/ig);
				if((tbesEventStatus.length+(cArr == null ? 0:cArr.length))>30)
				{
					updateaddTips("事件状态不能超出15个汉字");return false;
				}
				else if(tbesEventStatus==null||tbesEventStatus.length==0) {updateaddTips("事件状态不能为空");return false;}
				else if((cArr2 == null ? 0:cArr2.length)>0){updateaddTips("颜色格式不正确");return false;}
				else if(tbesColor.length>7){updateaddTips("颜色格式不正确");return false;}
				//若所有验证都通过，就确定
				else $('#addConfirm').dialog('open');
					
		
				},
				'取消' : function() 
				{
					$("#addltName").val("");
					$("#addltColor").val("");
					updateaddTips("");
					addtips.removeClass('ui-state-highlight');
					$(this).dialog('close');
				}
			},
			close : function()
			{
				$("#addltName").val("");
				$("input[name='addltColor']").val("ffffff");
				$("input[name='addltColor']").css("background-color","#ffffff");
				updateaddTips("");
				$("dialog").dialog('close');
			}
		});

		$('#addbut').click(function(){
			
			 
			$("#add").dialog("option","width",400);
			addtips.removeClass('ui-state-highlight');
			$('#add').dialog('open');
			
		});
		 $('#addltColor').colourPicker(
				 	{
	  		  		 ico:"/ag/zrt/images/jquery.colourPicker.gif", 
	   				 title:false
					});
		
	});